package com.chance.cc.crawler.development.bootstrap.xcar.sell;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

import java.util.Random;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/**
 * @ClassName 爱卡车型车系采集
 * @Description TODO
 * @Author songding
 * @Date 2021/8/9 13:14
 * @Version 1.0
 **/
public class AkIdStart {
    public static void main(String[] args) {
        gatherSeries();
    }

    /*
    * 爱卡车型车系采集
    * */
    private static final String DOMAIN = "xcar";
    private static final String SIDE = "gather";
    public static void gatherSeries(){
        String url = "https://newcar.xcar.com.cn/";//爱卡汽车网
        CrawlerRequestRecord  record = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(url)
                .domain(DOMAIN)
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(DOMAIN))
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*30,null))
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                //.resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                //.resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .build();
        record.tagsCreator().bizTags().addSite(SIDE);
        record.tagsCreator().bizTags().addSiteBiz(SIDE);
        record.tagsCreator().bizTags().addDomain(DOMAIN);
        record.tagsCreator().bizTags().addCustomKV("domainName",DOMAIN);
        record.tagsCreator().bizTags().addCustomKV("ak47","爱卡经销商");


        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, turnPageItem)
                .httpUrl("http://192.168.1.217:9599/v1/meta/xcar/keys?site=series_name")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();


        DevCrawlerController.builder()
                .triggerInfo(DOMAIN,DOMAIN,System.currentTimeMillis(),DOMAIN)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(DOMAIN))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka","F:\\chance_log\\xcar\\gather\\series.log",false)
                .requestRecord(record)
                .supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.xcar")
                .start();
    }

    public static void gatherSeriesTest(){
        String url = "https://newcar.xcar.com.cn/";//爱卡汽车网
        CrawlerRequestRecord  record = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(url)
                .domain(DOMAIN)
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(DOMAIN))
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                //.resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                //.resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .build();
        record.tagsCreator().bizTags().addSite(SIDE);
        record.tagsCreator().bizTags().addSiteBiz(SIDE);
        record.tagsCreator().bizTags().addDomain(DOMAIN);
        record.tagsCreator().bizTags().addCustomKV("domainName",DOMAIN);
        record.tagsCreator().bizTags().addCustomKV("ak47","爱卡经销商");


        String brand = "大众";
        String series = "上汽大众";
        String carModel = "帕萨特";
        record.tagsCreator().bizTags().addCustomKV("brand",brand);
        record.tagsCreator().bizTags().addCustomKV("series",series);
        record.tagsCreator().bizTags().addCustomKV("carModel",carModel);

        DevCrawlerController.builder()
                .triggerInfo(DOMAIN,DOMAIN,System.currentTimeMillis(),DOMAIN)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(DOMAIN))
                .consoleResultPipeline()
                .fileResultPipeline("F:\\chance_log\\xcar\\gather\\series.log",false)
                .requestRecord(record)
                .build("com.chance.cc.crawler.development.scripts.xcar")
                .start();
    }






    @Test
    public void test(){
        String a = "&lt;a href=&quot;/car/0-0-0-0-1-0-0-0-0-0-0-0/&quot; data-id=&quot;1&quot;&gt;                            ";
        String b ="&lt;/span&gt;                            奥迪                                                    ";
        String c = "&lt;span class=&quot;sign&quot;&gt; ";
        String s = b.replaceAll("&lt;", "")
                .replaceAll("&quot;","")
                .replaceAll("&gt;","")
                .replaceAll(" ","").replaceAll("ahref=","").replaceAll("data-id=","");
       if (s.matches("/car/\\S*")){
           System.out.println(s);
           String[] split = s.split("/");
           System.out.println(split[1]);
           System.out.println(split[2]);
           System.out.println(split[1]+"/"+split[2]+"/");
       }else if(s.matches("/span\\S*")){

            System.out.println(s.substring(5,s.length()));
        }else{
            System.out.println("错了");
        }

    }
    @Test
    public void tes(){
        String url = "https://newcar.xcar.com.cn/52/";
        String[] split = url.split("/");
        String i = "桑塔纳・·浩纳";
        i = i.replaceAll("\\s*","");
        System.out.println(i);
        System.out.println(i.equals("桑塔纳··浩纳"));
        System.out.println(split[3]);
        int a = new Random().nextInt(1000);
        System.out.println("0."+String.valueOf(System.currentTimeMillis())+String.valueOf(i));
    }
}


